import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:sph_shipper/Main/MyWallet/FreezeAmount.dart';


import '../../AppConfig/Config.dart';
import '../../AppConfig/RouteAct.dart';
import '../../http/NoLoadingGetApi.dart';
import '../../l10n/messages.dart';
import '../Settings/SettingList.dart';
import 'BankCardList.dart';
import 'BillListView.dart';
import 'DepositManagement.dart';
import 'PaymentManagement.dart';
import 'RechargeView.dart';
import 'Withdrawal.dart';
import 'WithdrawalBalance.dart';

class MyWallet extends StatefulWidget {
  const MyWallet({super.key});

  @override
  State<MyWallet> createState() => _MyWalletState();
}

class _MyWalletState extends State<MyWallet> {
  int checkBill =1;
  Map dataMap={};
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getBalance();
  }
  void getBalance(){
    NoLoadinggetApiManager.getData(
      context, // 上下文对象，用于显示提示信息等
      'api/pay/shipper/user/balanceInfo', // 您的API端点
      {}, // 查询参数，如果没有可以传递null
          (responseData)  {
        setState(() {
          dataMap=responseData['data'];
        });
      },
    );
  }
  @override
  Widget build(BuildContext context) {
    var messages = AppLocalizations.of(context)!;
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        backgroundColor: Colors.white,
        centerTitle: true,
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios, color: Colors.black),
          onPressed: () => Navigator.of(context).pop(),
        ),
        title: Text(messages['我的钱包'],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w300,fontSize: 16.sp),),

      ),
        body: ListView(
          children: [
            Container(
              height: 340.h,
             child:Stack(
               children: [
                 Container(

                   margin: EdgeInsets.only(top: 8.h,left: 10.w,right: 10.w),
                   padding: EdgeInsets.only(top: 20.h,left: 10.w,right: 10.w),
                   height: 212.h,
                   decoration: BoxDecoration(
                     borderRadius: BorderRadius.all(Radius.circular(10)),
                     gradient: LinearGradient(
                       begin: Alignment.topCenter,
                       end: Alignment.bottomCenter,
                       colors: [MyColors.themeColor, Color.fromRGBO(255,206,89,1)],

                     ),
                   ),
                   child: Column(
                     children: [
                       Row(
                         mainAxisAlignment: MainAxisAlignment.center,
                         children: [
                           Text("总资产(元)",style: TextStyle(fontSize: 13.sp,fontWeight: FontWeight.w600,color: Colors.white),),
                           GestureDetector(
                             child: checkBill==1?
                             Image.asset("lib/Images/PersonCenter/隐藏余额icon.png",width: 20.w,height: 14.h,color: Colors.white,)
                                 :Image.asset("lib/Images/PersonCenter/显示余额icon.png",width: 20.w,height: 14.h,color: Colors.white,),
                             onTap: (){
                               setState(() {
                                 if (checkBill==1){
                                   checkBill=2;
                                 }else{
                                   checkBill=1;
                                 }
                               });
                             },
                           ),
                         ],
                       ),
                       SizedBox(height: 8.h,),
                       Row(
                         mainAxisAlignment: MainAxisAlignment.center,
                         children: [
                           checkBill==1?
                           Text(dataMap['balance']!=null?dataMap['balance']:"0.00",style: TextStyle(fontSize: 28.sp,fontWeight: FontWeight.w600,color: Colors.white),)
                           :Text("*****",style: TextStyle(fontSize: 28.sp,fontWeight: FontWeight.w600,color: Colors.white),),
                         ],
                       ),
                       SizedBox(height: 22.h,),

                       Row(
                         children: [
                           GestureDetector(
                             child: Text("担保中金额"+(dataMap['depositAmount']!=null?dataMap['depositAmount']:"0.00")+">",style: TextStyle(fontSize: 13.sp,color: Colors.white),),
                             onTap: (){
                               Navigator.push( context, FadeRoute(page:DepositManagement(
                               )));
                             },
                           ),
                        ]
                       ),
                       SizedBox(height: 10.h,),
                       Row(
                         children: [
                           GestureDetector(
                             child: Container(
                               decoration: BoxDecoration(
                                   border: Border.all(
                                     color: Colors.white, // Set the color of the border
                                     width: 1.0.w, // Set the width of the border
                                   ),


                                   borderRadius: BorderRadius.all(Radius.circular(30))),

                               child:Center(
                                 child:   Text("提现",style: TextStyle(fontSize: 14.sp,color: Colors.white,fontWeight: FontWeight.w600),),
                               ),

                               width: 120.w,
                               height: 30.h,
                             ),
                             onTap: (){
                               Navigator.push( context, FadeRoute(page:WithdrawalBalance(
                               )));

                             },
                           ),
                           SizedBox(width: 8.w,),
                           GestureDetector(
                             child: Container(
                               decoration: BoxDecoration(
                                   color:Colors.white,
                                   borderRadius: BorderRadius.all(Radius.circular(30))),

                               child:Center(
                                 child: Text("充值",style: TextStyle(fontSize: 14.sp,color:MyColors.themeColor,fontWeight: FontWeight.w600),),
                               ),
                               width: 120.w,
                               height: 30.h,
                             ),
                             onTap: (){
                               Navigator.push( context, FadeRoute(page:RechargeView(
                               )));


                             },
                           ),
                         ],
                         mainAxisAlignment: MainAxisAlignment.center,
                       ),
                     ],
                   ),
                 ),
                 Positioned(
                   top:180.h,
                   child: Container(
                      // padding: EdgeInsets.only(left: 15.w,right: 15.w),
                     margin: EdgeInsets.only(left: 15.w,right: 15.w),
                     width: MediaQuery.of(context).size.width-30.w,
                     height: 100.0,
                     decoration: BoxDecoration(
                       borderRadius: BorderRadius.all(Radius.circular(10)),
                       color: Colors.white,
                     ),
                     child: Row(
                       mainAxisAlignment: MainAxisAlignment.spaceBetween,
                       children: [
                         BrnIconButton(
                             name: messages["银行卡"],
                             style: TextStyle(
                               fontSize: 13.sp,
                               color: Colors.black,
                             ),
                             direction: Direction.bottom,
                             padding: 4.h,
                             iconHeight: 26.h,
                             iconWidth: 26.w,
                             iconWidget: Image.asset("lib/Images/PersonCenter/银行卡icon.png"),
                             onTap: () {
                               Navigator.push( context, FadeRoute(page:BankCardList(
                               )));

                             }),
                         Container(
                           color: MyColors.backgreyColor,
                           height: 30.h,
                           width: 1.w,
                         ),
                         BrnIconButton(
                             name: "钱包账单",
                             style: TextStyle(
                               fontSize: 13.sp,
                               color: Colors.black,
                             ),
                             direction: Direction.bottom,
                             padding: 4.h,
                             iconHeight: 26.h,
                             iconWidth: 26.w,
                             iconWidget: Image.asset("lib/Images/PersonCenter/账单详情icon.png"),
                             onTap: () {
                               Navigator.push( context, FadeRoute(page:BillListView(
                               )));

                             }),
                         Container(
                           color: MyColors.backgreyColor,
                           height: 30.h,
                           width: 1.w,
                         ),
                         BrnIconButton(
                             name: messages["订金管理"],
                             style: TextStyle(
                               fontSize: 13.sp,
                               color: Colors.black,
                             ),
                             direction: Direction.bottom,
                             padding: 4.h,
                             iconHeight: 26.h,
                             iconWidth: 26.w,
                             iconWidget: Image.asset("lib/Images/PersonCenter/订金管理icon.png"),
                             onTap: () {
                               Navigator.push( context, FadeRoute(page:DepositManagement(
                               )));
                             }),
                         Container(
                           color: MyColors.backgreyColor,
                           height: 30.h,
                           width: 1.w,
                         ),
                         BrnIconButton(
                             name: messages["支付管理"],
                             style: TextStyle(
                               fontSize: 13.sp,
                               color: Colors.black,
                             ),
                             direction: Direction.bottom,
                             padding: 4.h,
                             iconHeight: 26.h,
                             iconWidth: 26.w,
                             iconWidget: Image.asset("lib/Images/PersonCenter/支付管理icon.png"),
                             onTap: () {
                               Navigator.push( context, FadeRoute(page:PaymentManagement(
                               )));

                             }),
                       ],

                     ),
                   ),
                 ),
               ],
             ) ,
            )

          ],
        ),
    );
  }
}
